Please describe in brief with an example.
Generics in C#
1626
14-Dec-2018
Anonymous User
14-Dec-2018Generics in C#
Here, Today, I would like to share the basics of generics. The Generic in C# is a concept that allows us to define classes and methods with the placeholder. The C# compiler replaces these placeholders with specified type at compile time. That is the concept of generics is used to create general-purpose classes and methods. When defining a generic class, we must use angle <> brackets. The angle brackets are used to declare a class or method as a generic type. In the following example, we are creating a generic class that can be used to deal with any type of data. Generics are so important because of that, we acquire the ability to create such classes, structures, interfaces, methods, and delegates, which work in type-safe for different types of data. The Generics(class or methods) in C# and .NET procedure many of the benefits of strongly-typed collections as well as provide a higher quality of and a performance boost for the code. The Generics are very similar to C++ templates but having a slight difference in such a way that the source code of C++ templates is required when the templates are instantiated with the specific type and .NET Generics are not limited to classes only.
Example - 1
Example - 2.